package com.trainingcloud.action.document;

import java.util.Vector;

import org.dom4j.Element;

import com.trainingcloud.XMLSerializer;
import com.trainingcloud.action.BaseSessionAction;
import com.trainingcloud.dao.DocumentDAO;
import com.trainingcloud.entity.ClientDocument;
import com.trainingcloud.exception.DAOException;
import com.trainingcloud.exception.SystemException;

public class SearchAction extends BaseSessionAction 
{
	private String query;
	
	public SearchAction() throws SystemException 
	{
		super();
	}

	@Override
	public String callWithSession() throws DAOException, SystemException 
	{
		DocumentDAO documentDAO = new DocumentDAO();		
		
		Vector<ClientDocument> result = documentDAO.searchDocuments(currentUser.getId(), query);
		
		Element listElement = responseElement.addElement("documentList");
		for(int i=1; i<=result.size(); i++)
		{
			XMLSerializer.clientDocumentToXML(result.get(i-1), listElement);
		}
		
		return null;
	}

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

}
